// 记录公共方法
#pragma once
#include <string>

// 记录错误码
enum ErrCode
{
    OK = 0,
    USAGE_ERR,
    SOCKET_ERR,
    BIND_ERR,
    LISTEN_ERR,
    CONNECT_ERR,
    WRITE_ERR,
    READ_ERR,
    FORK_EXIT
};

class nocopy
{
public:
    nocopy() = default;
    // 拷贝和赋值全部屏蔽
    nocopy(const nocopy &no) = delete;
    nocopy &operator=(const nocopy &no) = delete;
};

#define ADDR_PTR(addr_in) ((sockaddr *)&addr_in)

// 按行解析的方法 传入字符串，返回解析后的字符串
bool ParseOneLine(std::string &str, std::string &line, const std::string sep)
{
    size_t pos = str.find(sep);
    if (pos == std::string::npos)
        return false;
    line = str.substr(0, pos);
    str.erase(0, pos + sep.size()); // 截断解析过的一行
    return true;
}

//提取key value的方法
bool ParseKeyValue(std::string& str,std::string& key,std::string& value,const std::string&middle_sep)
{
    size_t pos = str.find(middle_sep);
    if(pos == std::string::npos)
        return false;
    key = str.substr(0,pos);
    value = str.substr(pos+middle_sep.size());
    return true;
}